(function($) {
	
	
	$.mask={
		
			mask:{maskdiv:null,tipdiv:null},
			
			maskresize:function()
			{				
				if(	$.mask.mask.maskdiv.css("width").replace("px","") != $(document.body).outerWidth(true) || $.mask.mask.maskdiv.css("height").replace("px","") != $(window).height())
				{  	$.mask.mask.maskdiv.css({display:"block",width:$(document.body).outerWidth(true),height:$(window).height()});
				    $.mask.mask.tipdiv.css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2}); 
				}		
			},	
			show:function(html)
			{
				if (html == undefined){
					html = "数据加载中，请稍候...";
				}
				$.mask.mask.maskdiv = $("<div id=\"tdqsv\" class=\"datagrid-mask\"></div>") ;
				$.mask.mask.tipdiv =   $("<div id=\"tdqsv1\" class=\"datagrid-mask-msg\"></div>");
				$.mask.mask.maskdiv.css({display:"block",width:$(document.body).outerWidth(true),height:$(window).height()}).appendTo("body");
				$.mask.mask.tipdiv.html(html).appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2}); 
				$.mask.mask.maskdiv.bgIframe();
				$(window).unbind("resize",this.maskresize);
			   $(window).bind("resize",this.maskresize);
			},
			close: function()
			{
			
				$.mask.mask.tipdiv.remove();
				$.mask.mask.maskdiv.remove();
				$(window).unbind("resize",this.maskresize);
			}
			
			
	};

          $.extend($.messager,
			{		   
			    tdqsAlert: function(title,msg,icon,fn)
			    {							      
						var _1e5="<div>"+msg+"</div>";
						switch(icon){
						case "error":
						_1e5="<div class=\"messager-icon messager-error\"></div>"+_1e5;
						break;
						case "info":
						_1e5="<div class=\"messager-icon messager-info\"></div>"+_1e5;
						break;
						case "question":
						_1e5="<div class=\"messager-icon messager-question\"></div>"+_1e5;
						break;
						case "warning":
						_1e5="<div class=\"messager-icon messager-warning\"></div>"+_1e5;
						break;					
						case "success":
						_1e5="<div class=\"messager-icon messager-success\"></div>"+_1e5;					
						break;
						}
						_1e5+="<div style=\"clear:both;\"/>";
						var _1e6={};
						_1e6[$.messager.defaults.ok]=function(){
						win.dialog({closed:true});
						if(fn){
						fn();
						return false;
						}
						};
						_1e6[$.messager.defaults.ok]=function(){
						win.window("close");
						if(fn){
						fn();
						return false;
						}
						};
						
	
							var win=$("<div class=\"messager-body\"></div>").appendTo("body");						
							win.append(_1e5);						
							if(_1e6){						
							var tb=$("<div class=\"messager-button\"></div>").appendTo(win);						
							for(var _1e2 in _1e6){						
							$("<a  id='alterok'></a>").attr("href","javascript:void(0)").text(_1e2).css("margin-left",10).bind("click",eval(_1e6[_1e2])).appendTo(tb).linkbutton();
											
							}						
							}						
							win.window({title:title,width:300,height:"auto",modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,onClose:function(){
						
							setTimeout(function(){						
								win.window("destroy");		
						
							},100);
						
							}});
							$(".window-mask").bgIframe();
							$("#alterok").focus();
							$("#alterok").bind("blur",function(){$("#alterok").focus()});						
							return win;
						
						
			    }	

		,confirm:function(_1e7,msg,fn){
		
				var _1e8="<div class=\"messager-icon messager-question\"></div>"+"<div>"+msg+"</div>"+"<div style=\"clear:both;\"/>";
				var _1e9={};
		
				_1e9[$.messager.defaults.ok]=function(){	
					win.window("close");
						if(fn){
						fn(true);
						return false;
						}
				};
				_1e9[$.messager.defaults.cancel]=function(){
						win.window("close");					
						if(fn){
						fn(false);
						return false;
						}
				};	
				
				
			var win=winconfirm(_1e7,_1e8,_1e9);
		}

,confirmex:function(config){

	/*
	 *     var config = {
				title: '标题',
				msg: '内容',
				buttons:{ok:"保存",cancel:"取消",close:"返回"},
				cancel: function(){document.title="cancel"},
				ok: function(){document.title="ok"},
				close:function(){ document.title="close"}
			}

	 */

	var _1e8="<div class=\"messager-icon messager-question\"></div>"+"<div>"+config.msg+"</div>"+"<div style=\"clear:both;\"/>";
	var _1e9={};
		_1e9[config.buttons.ok]=function(){	 
			   win.window("close");
				if(config.ok){
					config.ok();
				return false;
				}
		};
		_1e9[config.buttons.cancel]=function(){
				win.window("close");	
				if(config.cancel){
					config.cancel();
				return false;
				}
		};	

		

		if(config.buttons.close)
		{
		_1e9[config.buttons.close]=function(){
				win.window("close");	
				if(config.close){
					config.close();
				return false;
				}
	    };	
		}
		var win=winconfirm(config.title,_1e8,_1e9,config);

	}







 });
		    
 function winconfirm(_1df,_1e0,_1e1,config){

	var win=$("<div class=\"messager-body\"></div>").appendTo("body");

	win.append(_1e0);

	if(_1e1){

	var tb=$("<div class=\"messager-button\"></div>").appendTo(win);

	var i=0;

	for(var _1e2 in _1e1){

	i++;

	$("<a id='confirm"+i+"'></a>").attr("href","javascript:void(0)").text(_1e2).css("margin-left",10).bind("click",eval(_1e1[_1e2])).appendTo(tb).linkbutton();

	

	}

	}

	win.window({title:_1df,width:300,height:"auto",modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,onClose:function(){

	setTimeout(function(){

	win.window("destroy");

	},100);

	}});

	

	

	document.title = $(".window-mask").html();

	

	$(".window-mask").bgIframe();	

	

	var lastindex = i;

	if(config && config.foucs)

	{

		if( config.foucs =='cancel')

		{		

			i =2;

		}else if( config.foucs =='ok')

		{		

			i =1;

		}	

	}

	

	$("#confirm"+i).focus();

	

	

	$("#confirm"+lastindex).bind("blur",function(){$("#confirm1").focus()});

	

	

	return win;

	};
		/*    
	window.alert =function(msg,title,icon,fn)
	{
		if(jQuery.type(msg) == "object")
		{	
			if(msg.title ==null ||msg.title=='' ){
				msg.title ="提示";
			}
			
			if(msg.icon ==''){
				msg.icon = null;
			}
			
			if (!msg.msg){
				msg.msg = msg;
			}
			
			$.messager.tdqsAlert(msg.title,msg.msg,msg.icon,msg.completefunction);
			return;
		}		

		if(title ==null ||title=='' )
			title ="提示";
		if(icon =='')
			icon = null;
		$.messager.tdqsAlert(title,msg,icon,fn);
	};	*/
	
	window.confirm = function(msg,title,fn)

	{

		if(jQuery.type(msg)== "object")

		{		

			if(msg.title ==null ||msg.title=='' )

				msg.title ="提示";		

			

			 if(msg.buttons)

			 {				 

				 $.messager.confirmex(msg);				 

				  return;

			 }

			 

				

			$.messager.confirm(msg.title,msg.msg , function(r){				

				if(r) 

				{	if(msg.ok)

					msg.ok();					

				}else 

				{	

					if(msg.cancel)

					msg.cancel();

				}				

			} );			

			return;

		}else if(jQuery.type(title)=="function")

		{

		 fn =title;

		 title = null;			

		}		

		if(title ==null ||title=='' )

			title ="提示";

		$.messager.confirm(title,msg,fn);

	}



})(jQuery);
